﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KDSugar.Galaxy.API
{
    /// <summary>
    /// 辅助类
    /// </summary>
    public class Helper
    {
        /// <summary>
        /// 将数组按照分隔字符串串连并输出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="_arrays">需要用于分割的数组</param>
        /// <param name="_splitStr">分隔符</param>
        /// <returns></returns>
        public static string ArraysToString<T>(List<T> _arrays, string _splitStr = ",")
        {
            string result = null;
            if (_arrays != null && !string.IsNullOrWhiteSpace(_splitStr))
            {
                result = "";
                foreach (T t in _arrays)
                    result += t.ToString() + _splitStr;
                if (_arrays.Count > 0)
                    result = result.Substring(0, result.Length - _splitStr.Length);
            }
            return result;
        }

        /// <summary>
        /// 以追加的形式添加值到数组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="_arrays">数组</param>
        /// <param name="_val">要添加的值</param>
        public static void AppendArrays<T>(ref List<T> _arrays,T _val)
        {
            if (_arrays == null)
                _arrays = new List<T>();
            _arrays.Add(_val);
        }

        /// <summary>
        /// 通用KV名称类
        /// </summary>
        public class KVName
        {
            /// <summary>
            /// 语言内码
            /// </summary>
            public long Key { get; set; }

            /// <summary>
            /// 名称值
            /// </summary>
            public string Value { get; set; }
        }
    }
}
